package com.wx.references;

import lombok.extern.slf4j.Slf4j;

import java.lang.ref.SoftReference;
import java.util.ArrayList;

/**
 * 软引用
 * @description:
 * @author: wangxun
 * @createDate: 2021/12/31
 * @version: 1.0
 */
@Slf4j
public class SoftReferences {
    public static void main(String[] args) throws InterruptedException {

        // -Xmx20M 堆的大小设置为20MB
        SoftReference<Worker> workerSoftReference = new SoftReference<>(new Worker());



        log.info("worker:{}",workerSoftReference.get());
        ArrayList<byte[]> bytes = new ArrayList<>();
        // 向堆内存添加10MB
        bytes.add(new byte[1024*1024*10]);
        log.info("worker:{}",workerSoftReference.get());
        bytes.add(new byte[1024*1024*6]);
        log.info("worker:{}",workerSoftReference.get());
    }
}
